/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ken
 * Date: 2023-11-23
 * Time: 11:40
 */
class A{

}
public class Test {
    public static int countSegments(String s) {
        int count = 0;        //记录题目所说的单词的数量
        int index = 0;         //记录我们传过来的这个下标
        while (index < s.length()) {
            boolean flag = true;  //判断单词的开头，阻断连续的计数
            while ((index < s.length()) && (s.charAt(index) == ' ')) {
                index++;
            }
            while ((index < s.length()) && (s.charAt(index) != ' ')) {
                if(flag) {           //多个非空格的字符相连也算作提个字符
                    count++;
                    flag = false;
                }
                index++;
            }
        }
        return count;
    }
    public static void main(String[] args) {
        String s = " , , , ,      a, eaefa";
        int ret = countSegments(s);
        System.out.println(ret);
    }
}
